//
//  CustomTableViewCell.m
//  ceShi12
//
//  Created by RT on 2025/6/25.
//

#import "CustomTableViewCell.h"
@interface CustomTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@end
@implementation CustomTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleDefault;
        self.backgroundColor = UIColor.redColor;
        [self collectionView];
    }
    
    return self;
}
//TODO: 右下
-(XLPlainFlowLayout *)FlowLayout{
    
    if(!_FlowLayout){
        _FlowLayout = [[XLPlainFlowLayout alloc]init];
        _FlowLayout.naviHeight = 0;
        //        _FlowLayout.headerReferenceSize = CGSizeZero;
        //        _FlowLayout.footerReferenceSize = CGSizeZero;
        _FlowLayout.minimumInteritemSpacing = 0;
        _FlowLayout.minimumLineSpacing = 0;
        _FlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        //        _FlowLayout.sectionInset = UIEdgeInsetsZero; // 关键设置
    }
    
    return _FlowLayout;
}
-(void)setIndexPathCell:(NSIndexPath *)indexPathCell{
    _indexPathCell = indexPathCell;
    
}
- (UICollectionView *)collectionView{
    if(!_collectionView){
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 206, 30) collectionViewLayout:self.FlowLayout];
//         _collectionView.backgroundColor = UIColor.yellowColor;
        _collectionView.dataSource = self;
        _collectionView.delegate = self;

        //        _collectionView.scrollsToTop = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.bounces = NO;
        [_collectionView registerClass:[MarketFinance2Cell3 class] forCellWithReuseIdentifier:@"cell"];
        [self.contentView addSubview:_collectionView];
        
        //        _collectionView
    }
    
    return _collectionView;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(95, 30);
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    // 返回要显示的区的数量
    
    return 1;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    
    return 10;
    
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell1%ld%ld", (long)[indexPath section], (long)[indexPath row]];
    
    [self.collectionView registerClass:[MarketFinance2Cell3 class]  forCellWithReuseIdentifier:CellIdentifier];
    
    MarketFinance2Cell3 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.backgroundColor = UIColor.yellowColor;
    cell.name = [NSString stringWithFormat:@"%ld-%ld",_indexPathCell.row,indexPath.row];
    
    return cell;
    
    
}
-(void)setVC:(UIViewController *)VC{
    _VC = VC;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if([self.deletage respondsToSelector:@selector(CustomTableViewCellScrollViewDidScroll:)]){
        [self.deletage CustomTableViewCellScrollViewDidScroll:scrollView];
    }
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  
    if([self.deletage respondsToSelector:@selector(CustomTableViewCellScrollViewWillBeginDragging:)]){
        [self.deletage CustomTableViewCellScrollViewWillBeginDragging:scrollView];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
   
    if([self.deletage respondsToSelector:@selector(CustomTableViewCellScrollViewDidEndDecelerating:)]){
        [self.deletage CustomTableViewCellScrollViewDidEndDecelerating:scrollView];
    }
}


// 确保复用时不保留旧状态
//- (void)prepareForReuse {
//    [super prepareForReuse];
//    // 不移除代理，但重置滚动位置
////    if (!CGPointEqualToPoint([ViewController sharedGlobalOffset], CGPointZero)) {
////
////        [self.collectionView setContentOffset:[ViewController sharedGlobalOffset] animated:NO];
////    }
//}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
